package com.mew.slots.core.game.kbwsj.roller;


import cn.hutool.core.util.RandomUtil;
import com.mew.slots.core.common.roller.xml.BaseXml;

import java.util.ArrayList;

public class KbwsjXml extends BaseXml {

    private static KbwsjXml instance;

    private KbwsjXml(){}

    static {
        instance = new KbwsjXml();
    }

    public static KbwsjXml getInstance(){
        return instance;
    }

    @Override
    public void initPathsRowCol() throws Exception{
        //路径
        this.getPaths().add("external/roller/kbwsj/kbwsj_roller.xml");
        this.getPaths().add("external/roller/kbwsj/kbwsj_charge_roller.xml");
        this.bigWinPath = "external/roller/kbwsj/bigwin.txt";
        //3行5列
        this.setRow(3);
        this.setCol(5);
    }

    @Override
    public int parseInt(String str) {
        return 0;
    }


    public ArrayList<ArrayList<Integer>> getColLine(int path, int rollerID, int row, int col){

        /**
         * 重下往上补
         * 最开始显示最下面的
         */
        ArrayList<ArrayList<Integer>> cols = new ArrayList<>();

        //
        ArrayList<ArrayList<Integer>> roller = this.getAllRollers().get(path).get(rollerID);

        //5列
        for (int i = 0; i < col ; i++) {
            //轴上列
            ArrayList<Integer> lines = roller.get(i);
            //图上列
            ArrayList<Integer> colIcons = new ArrayList<>();
            //开始
            int start = RandomUtil.randomInt(lines.size());

            for (int j = 0; j < row; ) {
                if (start>=lines.size()){
                    start = 0;
                }
                Integer icon = lines.get(start);
                colIcons.add(icon);
                if (icon<11){
                    //不是金币
                    j++;
                }
                start++;
            }
            cols.add(colIcons);
        }

        return cols;
    }



    /**
     * 竖向转横向
     * @param cols
     * @return
     */
    public int[] col2row(ArrayList<ArrayList<Integer>> cols){

        //最长一列
        int max = cols.stream().mapToInt(ArrayList::size).max().getAsInt();
        //组装
        int[] solts = new int[max * col];

        for (int i = 0; i < cols.size(); i++) {
            ArrayList<Integer> colIcons = cols.get(i);
            //补长
            while (colIcons.size()<max){
                colIcons.add(-1);
            }
            //填图
            for (int j = colIcons.size() - 1; j >= 0; j--) {
                solts[j*col+i] = colIcons.get(j);
            }
            for (int j = 0; j < colIcons.size(); j++) {
                solts[j*col+i] = colIcons.get(colIcons.size()-j-1);
            }

        }
        return solts;
    }

    public static void main(String[] args) throws Exception {

    }


}
